<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_rapk View
	+ Description	: For record view
	+ Filename 		: v_t_rapk.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 10:52:52

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var t_komp_DataStore;
var t_komp_ColumnModel;
var t_komp_ListEditorGrid;
var t_komp_saveForm;
var t_komp_SelectedRow;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

var array_detail_jobdet_id = [];

/* on ready fuction */
Ext.onReady(function(){

	Ext.override(Ext.form.ComboBox, {
		setValue : function(v, fireSelect){
			var text = v;
			if(this.valueField){
				var r = this.findRecord(this.valueField, v);
				if(r){
					text = r.data[this.displayField];
					if (fireSelect) {
						this.fireEvent('select', this, r, this.store.indexOf(r));
					}
				}else if(Ext.isDefined(this.valueNotFoundText)){
					text = this.valueNotFoundText;
				}
			}
			this.lastSelectionText = text;
			if(this.hiddenField){
				this.hiddenField.value = v;
			}
			Ext.form.ComboBox.superclass.setValue.call(this, text);
			this.value = v;
			return this;
		}
	});
	
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  	
  	Ext.util.Format.comboRenderer = function(combo){
  	    return function(value){
  	        var record = combo.findRecord(combo.valueField, value);
  	        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
  	    };
  	};
  	
  	/* START DATA */
  	t_komp_DataStore = new Ext.data.Store({
		id: 't_komp_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'komp_id'
		},[
			{name: 'komp_id', type: 'int', mapping: 'komp_id'},
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'm_div_id', type: 'int', mapping: 'm_div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'vendor_id', type: 'int', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'},
			{name: 'komp_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'komp_date'},
			{name: 'komp_no', type: 'string', mapping: 'komp_no'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
  	t_komp_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
  	
	var expander_komp_list = new Ext.ux.grid.RowExpander({
        tpl : new Ext.Template(
                '<table>',
                '<tr>',
                '<td>',
                //'<p><b>Kode Proyek:</b> {komp_code}<br><b>Nama Proyek:</b> {komp_name}</p>',
                //'<p><b>Cabang:</b> {branch_name}<br><b>Singk. Proyek:</b> {komp_shortname}<br>',
                //'<b>Jenis Proyek:</b> {komp_type}<br><b>Nama PM:</b> {komp_pm}<br><b>Nama SEM/CM:</b> {komp_semcm}</p>',
                '</td>',
                '<td>',
                //'<p><b>NK:</b> {komp_value:rpMoney}<br><b>NK - PPN:</b> {komp_value_minusppn}',
                //'<br><b>Tgl Mulai:</b> {komp_start:date("l, F d, Y")}',
                //'<br><b>P1:</b> {komp_p1:date("l, F d, Y")}',
                //'<br><b>P2:</b> {komp_p2:date("l, F d, Y")}</p>',
                '</td>',
                '</tr>',
                '</table>'
            )
  	});
	
	var branchDataStore = new Ext.data.Store({
		id: 'branchDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_branch', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'branch_id'
		},[
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'branch_active', type: 'string', mapping: 'branch_active'},
			{name: 'dvo_id', type: 'int', mapping: 'dvo_id'},
			{name: 'dvo_name', type: 'string', mapping: 'dvo_name'}
		]),
		sortInfo:{field: 'branch_name', direction: "ASC"}
	});
	
	var project_codeDataStore = new Ext.data.Store({
		id: 'project_codeDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_project', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'project_id'
		},[
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'project_div', type: 'int', mapping: 'm_div_id'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
	var tpl_projectDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{project_code}]</b><br /></span>',
            '{project_name}',
            '</div></tpl>'
	);
	
	var jobDataStore = new Ext.data.Store({
		id: 'jobDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_job_bybranchprojectBelumMenang', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'job_id'
		},[
			{name: 'rapk_id', type: 'int', mapping: 'rapk_id'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'div_id', type: 'int', mapping: 'div_id'}
		]),
		sortInfo:{field: 'job_name', direction: "ASC"}
	});
	
	var m_jobdet_reader=new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total',
		id: 'jobdet_id'
	},[
	/* dataIndex => insert intoperawatan_ColumnModel, Mapping => for initiate table column */
			{name: 'rapkdet_id', type: 'int', mapping: 'rapkdet_id'},
			{name: 'kompdet_id', type: 'int', mapping: 'kompdet_id'}, 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'kompdet_unit', type: 'int', mapping: 'kompdet_unit'},
			{name: 'kompdet_vol', type: 'float', mapping: 'kompdet_vol'},
			{name: 'kompdet_rapkvolume', type: 'float', mapping: 'kompdet_rapkvolume'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'kompdet_rapkprice', type: 'float', mapping: 'kompdet_rapkprice'},
			{name: 'kompdet_price', type: 'float', mapping: 'kompdet_price'}
	]);
	
	var jobdetDataStore = new Ext.data.Store({
		id: 'jobdetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=kompdet_list', 
			method: 'POST'
		}),
		reader: m_jobdet_reader//,
		//sortInfo:{field: 'jobdet_id', direction: "ASC"}
	});

	var detailallDataStore = new Ext.data.Store({
		id: 'detailallDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=kompdet_list_all', 
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'groupdettemp_id', type: 'int', mapping: 'groupdettemp_id'}, 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'rapkdet_volume', type: 'float', mapping: 'rapkdet_volume'},
			{name: 'kompdet_volume', type: 'float', mapping: 'kompdet_volume'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'rapkdet_price', type: 'float', mapping: 'rapkdet_price'},
			{name: 'kompdet_price', type: 'float', mapping: 'kompdet_price'},
			{name: 'rapkdet_publish', type: 'bool', mapping: 'rapkdet_publish'}
		])
	});

	var detailDataStore = new Ext.data.Store({
		id: 'detailDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=t_kompdet_groupdettemp_getAll',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'groupdettemp_id', type: 'int', mapping: 'groupdettemp_id'}, 
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'rapkdet_volume', type: 'float', mapping: 'rapkdet_volume'},
			{name: 'kompdet_volume', type: 'float', mapping: 'kompdet_volume'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'rapkdet_price', type: 'float', mapping: 'rapkdet_price'},
			{name: 'kompdet_price', type: 'float', mapping: 'kompdet_price'},
			{name: 'rapkdet_publish', type: 'bool', mapping: 'rapkdet_publish'},
			{name: 'rapkdet_id', type: 'int', mapping: 'rapkdet_id'}
		])
}); 
	
	var groupDataStore = new Ext.data.Store({
		id: 'group_rapkdetTempDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=t_kompdet_grouptemp_getAll',
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total'
		},[
			{name: 'group_id', type: 'int', mapping: 'group_id'},
			{name: 'group_uraian', type: 'string', mapping: 'group_uraian'},
			{name: 'group_publish', type: 'bool', mapping: 'group_publish'},
			{name: 'group_new', type: 'bool', mapping: 'group_new'},
			{name: 'group_rapkprice', type: 'float', mapping: 'group_rapkprice'},
			{name: 'group_only', type: 'int', mapping: 'group_only'},
			{name: 'group_kompprice', type: 'float', mapping: 'group_kompprice'}
		])
	});
	
	var jobdet_allDataStore = new Ext.data.Store({
		id: 'jobdet_allDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=get_jobdet_all', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'jobdet_id'
		},[
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'},
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'rapkdet_id', type: 'int', mapping: 'rapkdet_id'}
		]),
		sortInfo:{field: 'jobdet_name', direction: "ASC"}
	});
	
	var tpl_jobdetDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{jobdet_name}]</b><br /></span>',
            'Material: {job_name}',
            '</div></tpl>'
	);
	
	var vendorDataStore = new Ext.data.Store({
		id: 'vendorDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_komp&m=get_vendor', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15, vendor_type: 'S', branch_id : 0,project_id : 0, job_id : 0},
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'vendor_id'
		},[
			{name: 'vendor_id', type: 'int', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'},
			{name: 'vendor_address', type: 'string', mapping: 'vendor_address'}
		]),
		sortInfo:{field: 'vendor_name', direction: "ASC"}
	});
	var tpl_vendorDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{vendor_name}]</b><br /></span>',
            '{vendor_address}',
            '</div></tpl>'
	);
	
	var unitDataStore = new Ext.data.Store({
		id: 'unitDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_unit', 
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'unit_id'
		},[
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'}
		]),
		sortInfo:{field: 'unit_name', direction: "ASC"}
	});
  	/* END DATA */
  	
  	
  	/* START FORM */
	//detail
	var kompdet_rapkdet_idField = new Ext.form.NumberField({
		id: 'kompdet_rapkdet_idField',
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		maskRe: /([0-9]+)$/
	});
	
	var komprapk_jobdet_total_cfField= new Ext.form.TextField({
		id: 'komprapk_jobdet_total_cfField',
		fieldLabel: '<span style="font-weight:bold">Total RAPK (Rp)</span>',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		maskRe: /([0-9]+)$/ 
	});
	
	var komp_jobdet_total_cfField= new Ext.form.TextField({
		id: 'komp_jobdet_total_cfField',
		fieldLabel: '<span style="font-weight:bold">Total KOMP (Rp)</span>',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		maskRe: /([0-9]+)$/ 
	});
	
	var komp_jobdet_totalGroup = new Ext.form.FieldSet({
		title: '-',
		labelWidth: 140,
		autoHeight: true,
		collapsible: false,
		layout:'form',
		frame: true,
		items:[komprapk_jobdet_total_cfField, komp_jobdet_total_cfField]
	});

	var kompdet_rapkdet_field_temp = new Ext.form.NumberField();
	var kompdet_rapkdet_selected = new Ext.form.NumberField({
		value: 0
	});
	
	var number_field = new Ext.form.NumberField({
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		maxLength: 10,
		maskRe: /([0-9]+)$/
	});
	
	var numbervol_field = new Ext.form.NumberField({
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		maxLength: 10,
		maskRe: /([0-9]+)$/
	});
	
	var numberrapkvol_field = new Ext.form.NumberField({
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		readOnly:true,
		maxLength: 10,
		maskRe: /([0-9]+)$/
	});
	
	var numbergroupprice_field = new Ext.form.NumberField({
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		readOnly:true,
		maxLength: 10,
		maskRe: /([0-9]+)$/
	});
	
	var kompdet_rapkdetField=new Ext.form.ComboBox({
		store: jobdet_allDataStore,
		mode: 'remote',
		displayField: 'jobdet_name',
		valueField: 'jobdet_id',
		loadingText: 'Searching...',
		typeAhead: false,
		pageSize: pageS,
		triggerAction: 'all',
		lazyRender:false,
		tpl: tpl_jobdetDS,
		itemSelector: 'div.search-item',
		listClass: 'x-combo-list-small',
		hideTrigger: false,
		forceSelection:true
	});
	
	kompdet_rapkdetField.on('select', function(){
		var record = kompdet_rapkdetField.findRecord(kompdet_rapkdetField.valueField, kompdet_rapkdetField.getValue());
		kompdet_rapkdet_idField.setValue(record.data.rapkdet_id);

		kompdet_rapkdet_selected.setValue(1);
		kompdet_rapkdet_field_temp.setValue(record.data.jobdet_id);
	});
	//column model jobdet
	var kompdet_unitField = new Ext.form.ComboBox({
		id: 'kompdet_unitField',
		store: unitDataStore,
		mode: 'remote',
		displayField:'unit_name',
		valueField: 'unit_id',
        editable: false,
        forceSelection: true,
		triggerAction: 'all'
	});
	
	var t_komp_jobdet_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Kompdet Id',
			dataIndex: 'kompdet_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Rapkdet Id',
			dataIndex: 'rapkdet_id',
			width: 150,
			sortable: false,
			hidden: true,
			editor: kompdet_rapkdet_idField
		},
		{
			header: 'Uraian',
			dataIndex: 'jobdet_name',
			width: 200,
			editor : new Ext.form.TextField({
				readOnly : true,
				disable : true
			})
		},
		{
			header: 'Jenis, Merk, dan Ukuran Material',
			id: 'jobdet_jenis_merk_ukuran',
			dataIndex: 'jobdet_id',
			editor : kompdet_rapkdetField,
			editable: 
				function(){
					if(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('rapkdet_id') == 0){
						return false;
					}else{
						return true;
					}
				},
			renderer: Ext.util.Format.comboRenderer(kompdet_rapkdetField)
		},
		{
			header: 'Vol',
			dataIndex: 'kompdet_rapkvolume',
			width: 50,
			sortable: false,
			align: 'right',
			editor: numberrapkvol_field,
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Sat',
			dataIndex: 'kompdet_unit',
			width: 80,
			sortable: false,
			editor: kompdet_unitField,
			renderer: Ext.util.Format.comboRenderer(kompdet_unitField)
		},
		{
			header: 'Harga',
			dataIndex: 'kompdet_rapkprice',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/,
				readOnly : true
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah',
			dataIndex: 'kompdet_rapkjumlah',
			width: 90,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.kompdet_rapkvolume * record.data.kompdet_rapkprice,'0.000/i');
            }
		},
		{
			header: 'Vol KOMP',
			dataIndex: 'kompdet_vol',
			width: 50,
			sortable: false,
			align: 'right',
			editor: numbervol_field,
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Harga KOMP',
			dataIndex: 'kompdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah KOMP',
			dataIndex: 'kompdet_jumlah',
			width: 90,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.kompdet_vol * record.data.kompdet_price,'0.000/i');
            }
		}]
	);
	
		var detail_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'rapkdet_id',
			dataIndex: 'rapkdet_id',
			hidden: true
		},
		{
			header: 'Uraian',
			dataIndex: 'jobdet_name',
			editor: new Ext.form.TextField({
				readOnly : true
			})
		}, // kompdet_volume
		{
			header: 'Jenis, Merk, dan Ukuran Material',
			id: 'jobdet_jenis_merk_ukuran',
			dataIndex: 'jobdet_id',
			editor : kompdet_rapkdetField,
			editable: 
				function(){
					if(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('rapkdet_id') == 0){
						return false;
					}else{
						return true;
					}
				},
			renderer: Ext.util.Format.comboRenderer(kompdet_rapkdetField)
		},
		{
			header: 'Vol',
			dataIndex: 'rapkdet_volume',
			width: 50,
			sortable: false,
			align: 'right',
			editor: numberrapkvol_field,
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Sat',
			dataIndex: 'unit_id',
			width: 80,
			sortable: false,
			editor: kompdet_unitField,
			renderer: Ext.util.Format.comboRenderer(kompdet_unitField)
		},
		{
			header: 'Harga',
			dataIndex: 'rapkdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/,
				readOnly : true
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah',
			dataIndex: 'kompdet_rapkjumlah',
			width: 90,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.rapkdet_price * record.data.rapkdet_volume,'0.000/i');
            }
		},
		{
			header: 'Vol KOMP',
			dataIndex: 'kompdet_volume',
			width: 50,
			sortable: false,
			align: 'right',
			editor: numbervol_field,
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Harga KOMP',
			dataIndex: 'kompdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			editor: new Ext.form.NumberField({
				allowDecimals: true,
				allowNegative: false,
				blankText: '0',
				maxLength: 15,
				maskRe: /([0-9]+)$/
			}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah KOMP',
			dataIndex: 'kompdet_jumlah',
			width: 90,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.kompdet_volume * record.data.kompdet_price,'0.000/i');
            }
		}]
	);
	detail_ColumnModel.defaultSortable= true;

	
 	var group_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'group_id',
			dataIndex: 'group_id',
			hidden: true
		},
		{
			header: 'Uraian',
			dataIndex: 'group_uraian',
			editor: new Ext.form.TextField({
				allowBlank: false
          	})
		},
		{
			header: 'Vol',
			dataIndex: 'group_only',
			editor: new Ext.form.TextField({
				allowBlank: false,
				readOnly :true
          	}),
			renderer: function(v, params, record){
				if (v == 1) {
				return '1 Paket'}
					else {return ''};
			}
		},
		{
			header: 'Harga Rapk',
			dataIndex: 'group_rapkprice',
			editor: new Ext.form.TextField({
				allowBlank: false,
				readOnly :true
          	}),
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Harga KOMP',
			dataIndex: 'group_kompprice',
			editor: numbergroupprice_field,
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		}
		]
	); 
	t_komp_jobdet_ColumnModel.defaultSortable= true;
	
	
	var editor_group= new Ext.ux.grid.RowEditor({
        saveText: 'Update',
        clicksToEdit:2,
        listeners: {
        	'canceledit': function(){
				groupDataStore.load({
									callback: function(opts, success, response){
										t_komp_groupListEditorGrid.getSelectionModel().selectRow(0);
									}
								});
			},
        	'afteredit': function(){
				var newdata = t_komp_groupListEditorGrid.getSelectionModel().getSelected().data;
                
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_komp&m=t_kompdet_grouptemp_create',
					params: {
						group_id	: newdata.group_id,
						group_uraian	: newdata.group_uraian,
						group_publish	: newdata.group_publish,
						group_kompprice : newdata.group_kompprice
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								t_komp_groupListEditorGrid.getStore().reload({
									callback: function(opts, success, response){
										t_komp_groupListEditorGrid.getSelectionModel().selectRow(0);
									}
								});
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
			},
		}
	});
	
	var editor_m_jobdet= new Ext.ux.grid.RowEditor({
        saveText: 'Update',
        clicksToEdit:2,
        listeners: {
        	'canceledit': function(){
            	kompdet_rapkdet_selected.setValue(0);
            	kompdet_rapkdetField.setValue(kompdet_rapkdet_field_temp.getValue());

            	var encoded_array_detail_jobdet_id = Ext.encode(array_detail_jobdet_id);

            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_detail_jobdet_id);
        		jobdet_allDataStore.load();
            },
            'beforeedit': function(){
				if(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('rapkdet_id') == 0){
					kompdet_rapkdetField.enable();
					number_field.enable();
					kompdet_unitField.enable();
					kompdet_rapkdetField.setReadOnly(false);
					number_field.setReadOnly(false);
					kompdet_unitField.setReadOnly(false);
				}else{
					kompdet_rapkdetField.setReadOnly(true);
					number_field.setReadOnly(true);
					kompdet_unitField.setReadOnly(true);
				}
				
            	kompdet_rapkdet_selected.setValue(0);
            	kompdet_rapkdet_field_temp.setValue(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('jobdet_id'));

            	var encoded_array_detail_jobdet_id = Ext.encode(array_detail_jobdet_id);
            	
            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_detail_jobdet_id);
        		jobdet_allDataStore.load();
            },
            'afteredit': function(){
            	if((kompdet_rapkdet_selected.getValue()==1) 
                    	&& (/^\d+$/.test(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('jobdet_id'))) 
                    	&& (array_detail_jobdet_id.indexOf(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('jobdet_id')) == (-1))){
            		array_detail_jobdet_id.push(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('jobdet_id'));
            	}
            	var encoded_array_detail_jobdet_id = Ext.encode(array_detail_jobdet_id);
            	
            	jobdet_allDataStore.setBaseParam('task', 'selected');
            	jobdet_allDataStore.setBaseParam('query', '');
        		jobdet_allDataStore.setBaseParam('selected_id', encoded_array_detail_jobdet_id);
        		jobdet_allDataStore.load();
        		kompdet_rapkdet_selected.setValue(0);


        		var detail_total_rapk = 0;
        		var detail_total_komp = 0;
        		
        		var detail_store = t_komp_jobdetListEditorGrid.getStore();
        		for(var i=0;i<detail_store.getCount();i++){
            		var vol = detail_store.getAt(i).data.kompdet_vol;
            		var hrg = detail_store.getAt(i).data.kompdet_price;
            		if(vol !== undefined && hrg !== undefined){
            			detail_total_rapk+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_rapkprice);
            			detail_total_komp+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_price);
            		}
        			
        		}
        		komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
        		komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
				
            }/*\,
        	'afteredit': function(){
        		var detail_total_rapk = 0;
        		var detail_total_komp = 0;
        		
        		var detail_store = t_komp_jobdetListEditorGrid.getStore();
        		for(var i=0;i<detail_store.getCount();i++){
            		var vol = detail_store.getAt(i).data.kompdet_vol;
            		var hrg = detail_store.getAt(i).data.kompdet_price;
            		if(vol !== undefined && hrg !== undefined){
            			detail_total_rapk+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_rapkprice);
            			detail_total_komp+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_price);
            		}
        			
        		}
        		komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
        		komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
        	} */
        }
    });
	//detail list editor grid jobdet
	var t_komp_jobdetListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_komp_jobdetListEditorGrid',
		//el: 'fp_m_jobdet',
		title: 'Detail Jenis Pekerjaan',
		height: 250,
		hidden : true,
		width: 980,
		autoScroll: true,
		store: jobdetDataStore, // DataStore
		colModel: t_komp_jobdet_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		plugins: [editor_m_jobdet],
		frame: true,
		autoExpandColumn: 'jobdet_jenis_merk_ukuran',
		//clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { 
			forceFit:false,
			getRowClass: function(record, index, rowParams){
				if(record.data.rapkdet_id !== 0){
					return 'rowClass1';
				}
				//return (Math.floor(index / 5.0) % 2 == 0) ? 'rowClass1' : 'rowClass2';
			}
		},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: jobdetDataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: m_jobdet_add
		}, '-',{
			text: 'Delete',
			ref: '../detDelBtn',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: m_jobdet_confirm_delete
		}
		]
	});
	
	// group //
	
	var t_komp_groupListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_komp_groupListEditorGrid',
		//el: 'fp_m_jobdet',
		title: 'Group Jenis Pekerjaan',
		height: 250,
		hidden : true,
		width: 980,
		autoScroll: true,
		store: groupDataStore, // DataStore
		colModel: group_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
		plugins : editor_group,
        margins: '0 5 5 5',
		frame: true,
		//clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { 
			forceFit:false,
			getRowClass: function(record, index, rowParams){
				if(record.data.rapkdet_id !== 0){
					return 'rowClass1';
				}
				//return (Math.floor(index / 5.0) % 2 == 0) ? 'rowClass1' : 'rowClass2';
			}
		},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: groupDataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: m_group_add
		}, '-',{
			text: 'Delete',
			ref: '../detDelBtn',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: m_group_confirm_delete
		}
		]
	});
	
	t_komp_groupListEditorGrid.getSelectionModel().on('rowselect', function(sm, rowIdx, r){
		detailDataStore.setBaseParam('group_id', sm.getSelected().get('group_id'));
		detailDataStore.load();
	});
	
	
	t_komp_groupListEditorGrid.on('afteredit', function(evt){
			var newdata = t_komp_groupListEditorGrid.getSelectionModel().getSelected().data;
                
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_komp&m=t_kompdet_grouptemp_create',
					params: {
						group_id	: newdata.group_id,
						group_uraian	: newdata.group_uraian,
						group_publish	: newdata.group_publish,
						group_kompprice : newdata.group_kompprice
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								t_komp_groupListEditorGrid.getStore().reload({
									callback: function(opts, success, response){
										t_komp_groupListEditorGrid.getSelectionModel().selectRow(0);
										detail_total_komp = 0;
										detail_total_rapk = 0;
										groupstore = t_komp_groupListEditorGrid.getStore();
										for(var i=0;i<groupstore.getCount();i++){
											detail_total_komp +=  groupstore.getAt(i).data.group_kompprice;
											detail_total_rapk +=  groupstore.getAt(i).data.group_rapkprice;
										}
											
										detailallDataStore.load({
											callback: function(opts, success, response){
												for(var i=0;i<detailallDataStore.getCount();i++){
													var vol = detailallDataStore.getAt(i).data.rapkdet_volume;
													var hrg = detailallDataStore.getAt(i).data.kompdet_price;
													if(vol !== undefined && hrg !== undefined){
														detail_total_rapk += (detailallDataStore.getAt(i).data.rapkdet_volume * detailallDataStore.getAt(i).data.rapkdet_price);
														detail_total_komp += (detailallDataStore.getAt(i).data.kompdet_volume * detailallDataStore.getAt(i).data.kompdet_price);
													}
												}
												komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
												komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
											}
										});
										
									}
								});
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
	});
	
	
	// detail //
	
	var editor_detaillist = new Ext.ux.grid.RowEditor({
        saveText: 'Update', 
        clicksToEdit:2,
        listeners: {
        	'canceledit': function(){
			},
			
            'beforeedit': function(){
			
				if(t_komp_detailListEditorGrid.getSelectionModel().getSelected().get('rapkdet_id') == 0){
					kompdet_rapkdetField.enable();
					number_field.enable();
					kompdet_unitField.enable();
					kompdet_rapkdetField.setReadOnly(false);
					number_field.setReadOnly(false);
					kompdet_unitField.setReadOnly(false);
				}else{
					kompdet_rapkdetField.setReadOnly(true);
					number_field.setReadOnly(true);
					kompdet_unitField.setReadOnly(true);
				}
			},
			
			'afteredit' : function(){
			/*
        		 * insert t_rapkdet_groupdettemp
       		 	 */
                var newdata = t_komp_detailListEditorGrid.getSelectionModel().getSelected().data;
       		 	var group = t_komp_groupListEditorGrid.getSelectionModel().getSelected().data;
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_komp&m=t_kompdet_groupdettemp_create',
					params: {
						group_id		: group.group_id,
						m_jobdet_id		: newdata.jobdet_id,
						rapkdet_volume	: newdata.rapkdet_volume,
						rapkdet_unit	: newdata.unit_id,
						rapkdet_price	: newdata.rapkdet_price,
						kompdet_price	: newdata.kompdet_price,
						kompdet_volume	: newdata.kompdet_volume,
						rapkdet_publish	: newdata.rapkdet_publish,
						groupdettemp_id : newdata.groupdettemp_id
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								t_komp_detailListEditorGrid.getStore().reload();
									var detail_total_rapk = 0;
									var detail_total_komp = 0;
									
												groupstore = t_komp_groupListEditorGrid.getStore();
												for(var i=0;i<groupstore.getCount();i++){
													detail_total_komp +=  groupstore.getAt(i).data.group_kompprice;
													detail_total_rapk +=  groupstore.getAt(i).data.group_rapkprice;
												}
											
									detailallDataStore.load({
										callback: function(opts, success, response){
											for(var i=0;i<detailallDataStore.getCount();i++){
												var vol = detailallDataStore.getAt(i).data.rapkdet_volume;
												var hrg = detailallDataStore.getAt(i).data.kompdet_price;
												if(vol !== undefined && hrg !== undefined){
													detail_total_rapk += (detailallDataStore.getAt(i).data.rapkdet_volume * detailallDataStore.getAt(i).data.rapkdet_price);
													detail_total_komp += (detailallDataStore.getAt(i).data.kompdet_volume * detailallDataStore.getAt(i).data.kompdet_price);
												}
											}
											komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
											komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
										}
									});
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
			}
		}
	});
			
	var t_komp_detailListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_komp_detailListEditorGrid',
		//el: 'fp_m_jobdet',
		title: 'Detail Jenis Pekerjaan',
		height: 250,
		hidden : true,
		width: 980,
		autoScroll: true,
		store: detailDataStore, // DataStore
		colModel: detail_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		frame: true,
		plugins : editor_detaillist,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { 
			forceFit:false,
			getRowClass: function(record, index, rowParams){
				if(record.data.rapkdet_id !== 0){
					return 'rowClass1';
				}
				//return (Math.floor(index / 5.0) % 2 == 0) ? 'rowClass1' : 'rowClass2';
			}
		},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: detailDataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			ref: '../detaddBtn',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: m_detail_add
		}, '-',{
			text: 'Delete',
			ref: '../detDelBtn',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: m_detail_confirm_delete
		}
		]
	});
	
	t_komp_detailListEditorGrid.detaddBtn.disable();
	t_komp_detailListEditorGrid.detDelBtn.disable();
		
	t_komp_groupListEditorGrid.on('click', function(){
	
		t_komp_detailListEditorGrid.detaddBtn.enable();
		t_komp_detailListEditorGrid.detDelBtn.enable();
		if(t_komp_groupListEditorGrid.selModel.getCount() == 1){
			if(t_komp_groupListEditorGrid.getSelectionModel().getSelected().get('group_only') != 0){
				numbergroupprice_field.setReadOnly(false);
			}else{
				numbergroupprice_field.setReadOnly(true);
			}
		
			if(t_komp_groupListEditorGrid.getSelectionModel().getSelected().get('group_new') == 1){
				t_komp_groupListEditorGrid.detDelBtn.enable();
			}else{
				t_komp_groupListEditorGrid.detDelBtn.disable();
			}
		}
	});
	
	t_komp_detailListEditorGrid.on('click', function(){
		if(t_komp_detailListEditorGrid.selModel.getCount() == 1){
			if(t_komp_detailListEditorGrid.getSelectionModel().getSelected().get('rapkdet_id') == 0){
				t_komp_detailListEditorGrid.detDelBtn.enable();
			}else{
				t_komp_detailListEditorGrid.detDelBtn.disable();
			}
		}
		
		var detail_total_rapk = 0;
        var detail_total_komp = 0;
		
									groupstore = t_komp_groupListEditorGrid.getStore();
									for(var i=0;i<groupstore.getCount();i++){
										detail_total_komp +=  eval(groupstore.getAt(i).data.group_kompprice);
										detail_total_rapk +=  eval(groupstore.getAt(i).data.group_rapkprice);
									}
									
//		detailallDataStore.load({
//			callback: function(opts, success, response){
				for(var i=0;i<detailallDataStore.getCount();i++){
					var vol = detailallDataStore.getAt(i).data.rapkdet_volume;
					var hrg = detailallDataStore.getAt(i).data.kompdet_price;
					if(vol !== undefined && hrg !== undefined){
						detail_total_rapk += eval(detailallDataStore.getAt(i).data.rapkdet_volume * detailallDataStore.getAt(i).data.rapkdet_price);
						detail_total_komp += eval(detailallDataStore.getAt(i).data.kompdet_volume * detailallDataStore.getAt(i).data.kompdet_price);
					}
				}
				
				komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
				komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
//			}
//		});
	});
	
	t_komp_jobdetListEditorGrid.on('click', function(){
		if(t_komp_jobdetListEditorGrid.selModel.getCount() == 1){
		
			if(t_komp_jobdetListEditorGrid.getSelectionModel().getSelected().get('rapkdet_id') == 0){
				t_komp_jobdetListEditorGrid.detDelBtn.enable();
			}else{
				t_komp_jobdetListEditorGrid.detDelBtn.disable();
			}
		}
		
        var detail_total_rapk = 0;
        var detail_total_komp = 0;
				
        var detail_store = t_komp_jobdetListEditorGrid.getStore();
		for(var i=0;i<detail_store.getCount();i++){
        	var vol = detail_store.getAt(i).data.kompdet_vol;
        	var hrg = detail_store.getAt(i).data.kompdet_price;
        	if(vol !== undefined && hrg !== undefined){
        		detail_total_rapk+= (detail_store.getAt(i).data.kompdet_rapkvolume * detail_store.getAt(i).data.kompdet_rapkprice);
				detail_total_komp+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_price);
           	}
        		
        }
        komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
        komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
				
	});
	
	
	//Form Create/Update
	var komp_idField= new Ext.form.NumberField({
		id: 'komp_idField',
		fieldLabel: 'Project Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var komp_branchField= new Ext.form.ComboBox({
		id: 'komp_branchField',
		fieldLabel: 'Cabang <font color=red>*</font>',
		store: branchDataStore,
		mode: 'remote',
		displayField:'branch_name',
		valueField: 'branch_id',
        editable: false,
        forceSelection: true,
		allowBlank: false,
        anchor: '95%',
		pageSize: 15,
		triggerAction: 'all',
		/*getDisplayValue: function() {
	        return Ext.String.htmlDecode(this.value);
	    }*/
		/*listeners: {
			select: function(){
				this.displayField(Ext.util.Format.htmlDecode(this.getRawValue()));
			}
		}*/
	});
	komp_branchField.on('select', function(){
		komp_branchField.disable();
		project_codeDataStore.setBaseParam('branch_id', komp_branchField.getValue());
		project_codeDataStore.load();
	});
	var komp_projectField= new Ext.form.ComboBox({
		id: 'komp_projectField',
		fieldLabel: 'Kode Proyek',
		store: project_codeDataStore,
		mode: 'local',
		displayField:'project_code',
		valueField: 'project_id',
        editable: true,
        anchor: '95%',
		pageSize: 15,
		itemSelector: 'div.search-item',
		tpl: tpl_projectDS,
		triggerAction: 'all'
	});
	komp_projectField.on('select', function(){
		komp_projectField.disable();
		var record = komp_projectField.findRecord(komp_projectField.valueField, komp_projectField.getValue());
		//komp_projectNameField.setValue(record.get(komp_projectField.displayField));
		komp_projectNameField.setValue(record.data.project_name);

		jobDataStore.setBaseParam('branch_id', komp_branchField.getValue());
		jobDataStore.setBaseParam('project_id', komp_projectField.getValue());
		jobDataStore.load();
	});
	var komp_projectNameField= new Ext.form.TextField({
		id: 'komp_projectNameField',
		fieldLabel: 'Nama Proyek',
		anchor: '95%',
		readOnly: true
	});
	var komp_jobField= new Ext.form.ComboBox({
		id: 'komp_jobField',
		fieldLabel: 'Jenis Pekerjaan',
		store: jobDataStore,
		mode: 'local',
		displayField:'job_name',
		valueField: 'job_id',
        editable: true,
        anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	komp_jobField.on('select', function(){
		var record = komp_jobField.findRecord(komp_jobField.valueField, komp_jobField.getValue());
		var detail_store =  t_komp_jobdetListEditorGrid.getStore();
		detail_store.setBaseParam('komp_id','');
		komp_jobField.disable();
		// mampir 
	//	console.log(komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data);
		if (komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.div_name  != '503. Sub Kontraktor' ){
		
			t_komp_jobdetListEditorGrid.setVisible(true);
			t_komp_groupListEditorGrid.setVisible(false);
			t_komp_detailListEditorGrid.setVisible(false);
			
			jobdet_allDataStore.setBaseParam('task', 'detail');
			jobdet_allDataStore.setBaseParam('query', ''); 
			jobdet_allDataStore.setBaseParam('master_id', record.data.rapk_id);
			jobdet_allDataStore.load({
				callback: function(opts, success, response){
					unitDataStore.load({
						callback: function(opts, success, response){
							jobdetDataStore.setBaseParam('master_id', record.data.rapk_id);
							jobdetDataStore.setBaseParam('start', 0);
							jobdetDataStore.setBaseParam('limit', 15);
							jobdetDataStore.load({
								callback: function(opts, success, response){
									var detail_total_rapk = 0;
									var detail_total_komp = 0;
									for(var i=0; i<jobdetDataStore.getCount(); i++){
									//	console.log(jobdetDataStore.getAt(i).data.kompdet_rapkvolume);
										detail_total_rapk += (jobdetDataStore.getAt(i).data.kompdet_rapkvolume * jobdetDataStore.getAt(i).data.kompdet_rapkprice);
										detail_total_komp += (jobdetDataStore.getAt(i).data.kompdet_vol * jobdetDataStore.getAt(i).data.kompdet_price);
									}
									komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
									komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));

									for(i=0; i<jobdet_allDataStore.getCount();i++){
										array_detail_jobdet_id.push(jobdet_allDataStore.getAt(i).data.jobdet_id);
									}
								}
							});
						}
					});
					
				}
			});
		
		vendorDataStore.setBaseParam('vendor_type',komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.div_id);
		
		}else{
			t_komp_jobdetListEditorGrid.setVisible(false);
			t_komp_groupListEditorGrid.setVisible(true);
			t_komp_detailListEditorGrid.setVisible(true);
			
			rapk_id = komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.rapk_id;
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_komp&m=get_action',
				params: { task: "GETDATA_SUBKON", rapk_id:  rapk_id },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
						detailallDataStore.load();
						groupDataStore.load();
						jobdet_allDataStore.setBaseParam('task', 'detail');
						jobdet_allDataStore.setBaseParam('query', ''); 
						jobdet_allDataStore.setBaseParam('master_id', record.data.rapk_id);
						jobdet_allDataStore.load({
							callback: function(opts, success, response){
								unitDataStore.load({
									callback: function(opts, success, response){
										jobdetDataStore.setBaseParam('master_id', record.data.rapk_id);
										jobdetDataStore.setBaseParam('start', 0);
										jobdetDataStore.setBaseParam('limit', 15);
										jobdetDataStore.load({
											callback: function(opts, success, response){
												var detail_total_rapk = 0;
												var detail_total_komp = 0;
												
												groupstore = t_komp_groupListEditorGrid.getStore();
												for(var i=0;i<groupstore.getCount();i++){
													detail_total_komp +=  groupstore.getAt(i).data.group_kompprice;
													detail_total_rapk +=  groupstore.getAt(i).data.group_rapkprice;
												}
											
											
												for(var i=0; i<jobdetDataStore.getCount(); i++){
													detail_total_rapk += (jobdetDataStore.getAt(i).data.kompdet_rapkvolume * jobdetDataStore.getAt(i).data.kompdet_rapkprice);
													detail_total_komp += (jobdetDataStore.getAt(i).data.kompdet_vol * jobdetDataStore.getAt(i).data.kompdet_price);
												}
												komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
												komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));

												for(i=0; i<jobdet_allDataStore.getCount();i++){
													array_detail_jobdet_id.push(jobdet_allDataStore.getAt(i).data.jobdet_id);
												}
											}
										});
									}
								});
								
							}
						});
						
						break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Gagal ambil data!',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;

					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});

				}
			});
			
		vendorDataStore.setBaseParam('vendor_type',komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.div_id);
		}
		vendorDataStore.setBaseParam('branch_id',komp_branchField.getValue());
		vendorDataStore.setBaseParam('project_id',komp_projectField.getValue());
		vendorDataStore.setBaseParam('job_id',komp_jobField.getValue());
		vendorDataStore.load();
		
	});
	var komp_vendorField= new Ext.form.ComboBox({
		id: 'komp_vendorField',
		fieldLabel: 'Nama Subkont',
		store: vendorDataStore,
		mode: 'remote',
		editable : true,
		displayField:'vendor_name',
		valueField: 'vendor_id',
		allowBlank: false,
        anchor: '95%',
		pageSize: 15,
		itemSelector: 'div.search-item',
		tpl: tpl_vendorDS,
		triggerAction: 'all'
	});
	var komp_dateField= new Ext.form.DateField({
		id: 'komp_dateField',
		fieldLabel: 'Tgl Penawaran',
		format : 'l, F d, Y',
		anchor: '95%'
	});
	var komp_noField= new Ext.form.TextField({
		id: 'komp_noField',
		fieldLabel: 'No. Surat',
		maxLength: 45,
		anchor: '95%'
	});
	var komp_validornotField= new Ext.form.Label({
		id: 'komp_validornotField',
		style: {
			marginLeft : '10px',
			marginTop: '5px'
		}
	});
	var komp_btnsearch_noField= new Ext.Button({
		tooltip: 'Apakah No. Surat sudah pernah digunakan?',
		iconCls:'icon-search',
		handler: nosurat_validation
	});
	
	var t_komp_btn_Save = new Ext.Button({
		text: BTN_SAVE,
		handler: t_komp_save
	});
	t_komp_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' Komparasi',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 1000,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_komp_save',
		layout:'form',
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[komp_idField ,komp_branchField ,komp_projectField ,komp_projectNameField ,komp_jobField]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[komp_vendorField ,komp_dateField,{
					layout: 'column',
					border: false,
					items:[{
						columnWidth:0.60,
						layout: 'form',
						border:false,
						items:[komp_noField]
					},{
						columnWidth:0.40,
						layout: 'column',
						border:false,
						items: [komp_btnsearch_noField,komp_validornotField]
					}]
				}]
			}]
		},t_komp_jobdetListEditorGrid ,t_komp_groupListEditorGrid ,t_komp_detailListEditorGrid ,komp_jobdet_totalGroup 
		,new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED }) ],
		buttons: [t_komp_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					t_komp_reset_form();
				}
			}
		]
	});
	
	//start main grid panel
	t_komp_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Project Id',
			dataIndex: 'komp_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Cabang',
			dataIndex: 'branch_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Kode Proyek',
			dataIndex: 'project_code',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Proyek',
			dataIndex: 'project_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Jenis Pekerjaan',
			dataIndex: 'job_name',
			width: 150,
			sortable: false
		}, {
			header: 'Nama Mitra',
			dataIndex: 'vendor_name',
			width: 150,
			sortable: false
		}	]);

	t_komp_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    t_komp_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    t_komp_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_komp_confirm_update
	});

    t_komp_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_komp_confirm_delete
	});

	t_komp_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_komp_ListEditorGrid',
		el: 'fp_t_komp',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_komp_DataStore, // DataStore
		cm: t_komp_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
		plugins: expander_komp_list,
	  	width: 1000,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_komp_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_komp_gbtn_add, '-',
		t_komp_gbtn_update, '-',
		t_komp_gbtn_delete, '-',
		new Ext.app.SearchField({
			store: t_komp_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_komp_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_komp_reset_search,
			iconCls:'icon-refresh'
		}/*,'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_komp_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_komp_print
		}*/
		]
	});
	t_komp_ListEditorGrid.render();
	
  	/* END FORM */
  	
  	
  	/* START FUNCTION */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return t_komp_ListEditorGrid.getSelectionModel().getSelected().get('komp_id');
		return 0;
	}
	
	//validation form
	function is_t_komp_form_valid(){
		return (komp_vendorField.isValid() && komp_branchField.isValid());
	}
	
	//saving data
	function t_komp_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

		if(is_t_komp_form_valid()){
			var komp_id_field=null;
			var komp_branch_field=null;
			var komp_project_field=null;
			var komp_job_field=null;
			var komp_vendor_field=null;
			var komp_date_field="";
			var komp_no_field=null;

			if(komp_idField.getValue()!== null){komp_id_field = komp_idField.getValue();}
			if(komp_branchField.getValue()!== null){komp_branch_field = komp_branchField.getValue();}
			if(komp_projectField.getValue()!== null){komp_project_field = komp_projectField.getValue();}
			if(komp_jobField.getValue()!== null){komp_job_field = komp_jobField.getValue();}
			if(komp_vendorField.getValue()!== null){komp_vendor_field = komp_vendorField.getValue();}
			if(komp_dateField.getValue()!==""){komp_date_field = komp_dateField.getValue().format('Y-m-d');}
			if(komp_noField.getValue()!== null){komp_no_field = komp_noField.getValue();}
			
			//push data detail
			var rapkdet_id_field = [];
			var kompdet_id_field = [];
			var jobdet_id_field = [];
			var kompdet_vol_field = [];
			var kompdet_rapkvolume_field = [];
			var kompdet_unit_field = [];
			var kompdet_rapkprice_field = [];
			var kompdet_price_field = [];
			var jobdet_store = t_komp_jobdetListEditorGrid.getStore();
			for(var i=0; i<jobdet_store.getCount(); i++){
				if(jobdet_store.getAt(i).data.jobdet_id!==undefined
						&& jobdet_store.getAt(i).data.jobdet_id!==''
							&& jobdet_store.getAt(i).data.jobdet_id!==0){
					rapkdet_id_field.push(jobdet_store.getAt(i).data.rapkdet_id);
					kompdet_id_field.push(jobdet_store.getAt(i).data.kompdet_id);
					jobdet_id_field.push(jobdet_store.getAt(i).data.jobdet_id);
					kompdet_vol_field.push(jobdet_store.getAt(i).data.kompdet_vol);
					kompdet_rapkvolume_field.push(jobdet_store.getAt(i).data.kompdet_rapkvolume);
					kompdet_unit_field.push(jobdet_store.getAt(i).data.kompdet_unit);
					kompdet_rapkprice_field.push(jobdet_store.getAt(i).data.kompdet_rapkprice);
					kompdet_price_field.push(jobdet_store.getAt(i).data.kompdet_price);
				}
			}
			var encoded_array_rapkdet_id = Ext.encode(rapkdet_id_field);
			var encoded_array_kompdet_id = Ext.encode(kompdet_id_field);
			var encoded_array_jobdet_id = Ext.encode(jobdet_id_field);
			var encoded_array_kompdet_vol = Ext.encode(kompdet_vol_field);
			var encoded_array_kompdet_rapkvolume = Ext.encode(kompdet_rapkvolume_field);
			var encoded_array_kompdet_unit = Ext.encode(kompdet_unit_field);
			var encoded_array_kompdet_rapkprice = Ext.encode(kompdet_rapkprice_field);
			var encoded_array_kompdet_price = Ext.encode(kompdet_price_field);
//   simpan if (komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.div_id  == 1){
if ( post2db == 'CREATE'){//typeof(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('m_div_id') ) == 'undefined' ){
	m_div_id = komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.div_name;
}else{
	m_div_id = t_komp_ListEditorGrid.getSelectionModel().getSelected().get('div_name');
}
if (Ext.isNumber( komp_vendor_field) || post2db == 'UPDATE'){
 
			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_komp&m=get_action',
				params: {
					div_id :  m_div_id,
					komp_id	: komp_id_field,
					branch	: komp_branch_field,
					project	: komp_project_field,
					job	: komp_job_field,
					vendor: komp_vendor_field,
					komp_date: komp_date_field,
					komp_no: komp_no_field,
					
					//data detail jenis pekerjaan
					rapkdet_id: encoded_array_rapkdet_id,
					kompdet_id: encoded_array_kompdet_id,
					jobdet_id: encoded_array_jobdet_id,
					kompdet_vol: encoded_array_kompdet_vol,
					kompdet_unit: encoded_array_kompdet_unit,
					kompdet_rapkprice: encoded_array_kompdet_rapkprice,
					kompdet_rapkvolume : encoded_array_kompdet_rapkvolume,
					kompdet_price: encoded_array_kompdet_price,
					task: post2db
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							t_komp_DataStore.reload();
							t_komp_reset_form();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			}); 
}else{
	Ext.MessageBox.show({
	title: 'Warning',
	msg: FAILED_VALID_FORM,
	buttons: Ext.MessageBox.OK,
	animEl: 'save',
	icon: Ext.MessageBox.WARNING
			});
}
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

		}
	}
	
	//reset form
	function t_komp_reset_form(){
		t_kompdet_grouptemp_truncate();
		post2db='CREATE';
		msg='created';
		
		t_komp_detailListEditorGrid.detaddBtn.disable();
		t_komp_detailListEditorGrid.detDelBtn.disable();
		komp_branchField.enable();
		komp_idField.reset();
		komp_idField.setValue(null);
		komp_projectField.enable();
		komp_projectField.reset();
		komp_projectField.setValue(null);
		komp_projectField.enable();
		komp_projectNameField.reset();
		komp_projectNameField.setValue(null);
		komp_branchField.reset();
		komp_branchField.setValue(null);
		komp_branchField.enable();
		komprapk_jobdet_total_cfField.reset();
		komprapk_jobdet_total_cfField.setValue(null);
		komp_jobdet_total_cfField.reset();
		komp_jobdet_total_cfField.setValue(null);
		komp_jobField.enable();
		komp_jobField.reset();
		komp_jobField.setValue(null);
		komp_jobField.enable();
		komp_vendorField.reset();
		komp_vendorField.setValue(null);
		komp_vendorField.enable();
		komp_dateField.reset();
		komp_dateField.setValue(null);
		komp_dateField.enable();
		komp_noField.reset();
		komp_noField.setValue(null);
		komp_noField.setReadOnly(false);
		t_komp_jobdetListEditorGrid.getStore().removeAll();
		t_komp_detailListEditorGrid.getStore().removeAll();
		t_komp_groupListEditorGrid.getStore().removeAll();
		
		t_komp_jobdetListEditorGrid.setVisible(false);
		t_komp_detailListEditorGrid.setVisible(false);
		t_komp_groupListEditorGrid.setVisible(false);
		komp_validornotField.setText("");
	}
	
	//set form
	function t_komp_set_form(){
		komp_idField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('komp_id'));
		komp_branchField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('branch_name'));
		komp_branchField.disable();
		komp_projectField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('project_code'));
		komp_projectField.disable();
		komp_projectNameField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('project_name'));
		komp_jobField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('job_name'));
		komp_jobField.disable();
		komp_vendorField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('vendor_name'));
		komp_vendorField.disable();
		komp_dateField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('komp_date'));
		komp_dateField.disable();
		komp_noField.setValue(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('komp_no'));
		komp_noField.setReadOnly(true);
	
		
		unitDataStore.load({
			callback: function(opts, success, response){
			
			// (komp_jobField.getStore().getAt(komp_jobField.selectedIndex).data.div_id  == 1
			console.log(t_komp_ListEditorGrid.getSelectionModel().getSelected().get('div_name'));
		if (t_komp_ListEditorGrid.getSelectionModel().getSelected().get('div_name') != '503. Sub Kontraktor' ){

				t_komp_jobdetListEditorGrid.getStore().removeAll();
				t_komp_detailListEditorGrid.getStore().removeAll();
				t_komp_groupListEditorGrid.getStore().removeAll();

				t_komp_jobdetListEditorGrid.setVisible(true);
				t_komp_detailListEditorGrid.setVisible(false);
				t_komp_groupListEditorGrid.setVisible(false);
				jobdet_allDataStore.setBaseParam('limit', 1000);
				jobdet_allDataStore.load({
					callback: function(opts, success, response){
						var detail_store = t_komp_jobdetListEditorGrid.getStore();
				//		alert(komp_idField.getValue()); // mampir 
						detail_store.setBaseParam('komp_id', komp_idField.getValue());//t_komp_ListEditorGrid.getSelectionModel().getSelected().get('komp_id'));
						detail_store.setBaseParam('start', 0);
						detail_store.setBaseParam('limit', 15);
						detail_store.setBaseParam('task', 'detail');
						detail_store.load({
							callback: function(opts, success, response){
								var detail_total_rapk = 0;
								var detail_total_komp = 0;
								for(var i=0; i<detail_store.getCount(); i++){
									detail_total_rapk += (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_rapkprice);
									detail_total_komp += (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_price);
								}
								komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
								komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
							}
						});
					}
				});
				
		}else{
		
				t_komp_jobdetListEditorGrid.getStore().removeAll();
				t_komp_detailListEditorGrid.getStore().removeAll();
				t_komp_groupListEditorGrid.getStore().removeAll();

				t_komp_jobdetListEditorGrid.setVisible(false);
				t_komp_detailListEditorGrid.setVisible(true);
				t_komp_groupListEditorGrid.setVisible(true);
				
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_komp&m=get_action',
				params: { task: "EDIT_SUBKON", rapk_id:  t_komp_ListEditorGrid.getSelectionModel().getSelected().get('komp_id') },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
						
							var detail_total_rapk = 0;
							var detail_total_komp = 0;
							
						groupDataStore.load({
							callback : function(){
							
									groupstore = groupDataStore;
									
									for(var i=0;i<groupstore.getCount();i++){
										detail_total_komp +=  groupstore.getAt(i).data.group_kompprice;
										detail_total_rapk +=  groupstore.getAt(i).data.group_rapkprice;
									}
								detailallDataStore.load({
						callback : function(a,s,d){	
									
											for(var i=0;i<detailallDataStore.getCount();i++){
					var vol = detailallDataStore.getAt(i).data.rapkdet_volume;
					var hrg = detailallDataStore.getAt(i).data.kompdet_price;
					if(vol !== undefined && hrg !== undefined){
						detail_total_rapk += (detailallDataStore.getAt(i).data.rapkdet_volume * detailallDataStore.getAt(i).data.rapkdet_price);
						detail_total_komp += (detailallDataStore.getAt(i).data.kompdet_volume * detailallDataStore.getAt(i).data.kompdet_price);
					}
				}
				komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
				komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));

							}
						});
						
							}
						});
						
						break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Gagal ambil data!',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;

					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});

				}
			});
			
		
		}
		
			}
		});
		
	
	}
	
	//display form to create/update
	function display_form_window(){
	
		t_kompdet_grouptemp_truncate();
		post2db='CREATE';
		msg='created';
		t_komp_reset_form();
	}
	
	//update main grid
	function t_komp_confirm_update(){
		/* only one record is selected here */
		if(t_komp_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_komp_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	//delete main grid
	function t_komp_confirm_delete(){
		// only one t_komp is selected here
		if(t_komp_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_komp_delete);
		} else if(t_komp_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_komp_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	function t_komp_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = t_komp_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(var i = 0; i< t_komp_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.komp_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_komp&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							t_komp_DataStore.reload();
							break;
						case 3:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Data ini sudah diproses tidak bisa dihapus',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
	
	//reset searching
	function t_komp_reset_search(){
		t_komp_DataStore.baseParams = { task: 'LIST' };
		t_komp_DataStore.reload({params: {start: 0, limit: pageS}});
	};
	
	//printing
	function t_komp_print(){
		var searchquery = "";
		var komp_id_print=null;
		var komp_flag_print=null;
		var komp_code_print=null;
		var komp_type_print=null;
		var komp_name_print=null;
		var komp_shortname_print=null;
		var komp_pm_print=null;
		var komp_semcm_print=null;
		var komp_value_print=null;
		var komp_start_print_date="";
		var komp_p1_print_date="";
		var komp_p2_print_date="";
		var m_branch_print=null;

		if(t_komp_DataStore.baseParams.query!==null){searchquery = t_komp_DataStore.baseParams.query;}
		if(t_komp_DataStore.baseParams.komp_id!==null){komp_id_print = t_komp_DataStore.baseParams.komp_id;}
		if(t_komp_DataStore.baseParams.komp_flag!==null){komp_flag_print = t_komp_DataStore.baseParams.komp_flag;}
		if(t_komp_DataStore.baseParams.komp_code!==null){komp_code_print = t_komp_DataStore.baseParams.komp_code;}
		if(t_komp_DataStore.baseParams.komp_type!==null){komp_type_print = t_komp_DataStore.baseParams.komp_type;}
		if(t_komp_DataStore.baseParams.komp_name!==null){komp_name_print = t_komp_DataStore.baseParams.komp_name;}
		if(t_komp_DataStore.baseParams.komp_shortname!==null){komp_shortname_print = t_komp_DataStore.baseParams.komp_shortname;}
		if(t_komp_DataStore.baseParams.komp_pm!==null){komp_pm_print = t_komp_DataStore.baseParams.komp_pm;}
		if(t_komp_DataStore.baseParams.komp_semcm!==null){komp_semcm_print = t_komp_DataStore.baseParams.komp_semcm;}
		if(t_komp_DataStore.baseParams.komp_value!==null){komp_value_print = t_komp_DataStore.baseParams.komp_value;}
		if(t_komp_DataStore.baseParams.komp_start!==""){komp_start_print_date = t_komp_DataStore.baseParams.komp_start;}
		if(t_komp_DataStore.baseParams.komp_p1!==""){komp_p1_print_date = t_komp_DataStore.baseParams.komp_p1;}
		if(t_komp_DataStore.baseParams.komp_p2!==""){komp_p2_print_date = t_komp_DataStore.baseParams.komp_p2;}
		if(t_komp_DataStore.baseParams.m_branch!==null){m_branch_print = t_komp_DataStore.baseParams.m_branch;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_komp&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			komp_id : komp_id_print,
			komp_flag : komp_flag_print,
			komp_code : komp_code_print,
			komp_type : komp_type_print,
			komp_name : komp_name_print,
			komp_shortname : komp_shortname_print,
			komp_pm : komp_pm_print,
			komp_semcm : komp_semcm_print,
			komp_value : komp_value_print,
		  	komp_start : komp_start_print_date,
		  	komp_p1 : komp_p1_print_date,
		  	komp_p2 : komp_p2_print_date,
			m_branch : m_branch_print,
		  	currentlisting: t_komp_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/t_komp_printlist.html','t_komplist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	
	//exporting excel
	function t_komp_export_excel(){
		var searchquery = "";
		var komp_id_2excel=null;
		var komp_flag_2excel=null;
		var komp_code_2excel=null;
		var komp_type_2excel=null;
		var komp_name_2excel=null;
		var komp_shortname_2excel=null;
		var komp_pm_2excel=null;
		var komp_semcm_2excel=null;
		var komp_value_2excel=null;
		var komp_start_2excel_date="";
		var komp_p1_2excel_date="";
		var komp_p2_2excel_date="";
		var m_branch_2excel=null;

		if(t_komp_DataStore.baseParams.query!==null){searchquery = t_komp_DataStore.baseParams.query;}
		if(t_komp_DataStore.baseParams.komp_id!==null){komp_id_2excel = t_komp_DataStore.baseParams.komp_id;}
		if(t_komp_DataStore.baseParams.komp_flag!==null){komp_flag_2excel = t_komp_DataStore.baseParams.komp_flag;}
		if(t_komp_DataStore.baseParams.komp_code!==null){komp_code_2excel = t_komp_DataStore.baseParams.komp_code;}
		if(t_komp_DataStore.baseParams.komp_type!==null){komp_type_2excel = t_komp_DataStore.baseParams.komp_type;}
		if(t_komp_DataStore.baseParams.komp_name!==null){komp_name_2excel = t_komp_DataStore.baseParams.komp_name;}
		if(t_komp_DataStore.baseParams.komp_shortname!==null){komp_shortname_2excel = t_komp_DataStore.baseParams.komp_shortname;}
		if(t_komp_DataStore.baseParams.komp_pm!==null){komp_pm_2excel = t_komp_DataStore.baseParams.komp_pm;}
		if(t_komp_DataStore.baseParams.komp_semcm!==null){komp_semcm_2excel = t_komp_DataStore.baseParams.komp_semcm;}
		if(t_komp_DataStore.baseParams.komp_value!==null){komp_value_2excel = t_komp_DataStore.baseParams.komp_value;}
		if(t_komp_DataStore.baseParams.komp_start!==""){komp_start_2excel_date = t_komp_DataStore.baseParams.komp_start;}
		if(t_komp_DataStore.baseParams.komp_p1!==""){komp_p1_2excel_date = t_komp_DataStore.baseParams.komp_p1;}
		if(t_komp_DataStore.baseParams.komp_p2!==""){komp_p2_2excel_date = t_komp_DataStore.baseParams.komp_p2;}
		if(t_komp_DataStore.baseParams.m_branch!==null){m_branch_2excel = t_komp_DataStore.baseParams.m_branch;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_komp&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			komp_id : komp_id_2excel,
			komp_flag : komp_flag_2excel,
			komp_code : komp_code_2excel,
			komp_type : komp_type_2excel,
			komp_name : komp_name_2excel,
			komp_shortname : komp_shortname_2excel,
			komp_pm : komp_pm_2excel,
			komp_semcm : komp_semcm_2excel,
			komp_value : komp_value_2excel,
		  	komp_start : komp_start_2excel_date,
		  	komp_p1 : komp_p1_2excel_date,
		  	komp_p2 : komp_p2_2excel_date,
			m_branch : m_branch_2excel,
		  	currentlisting: t_komp_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
		  		window.open('./print/t_komp_printlist.xls');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	
	function m_jobdet_add(){
		var edit_m_jobdet= new t_komp_jobdetListEditorGrid.store.recordType({
			kompdet_id: 0,
			rapkdet_id: 0,
			jobdet_id: 0,
			kompdet_vol: 0,
			kompdet_unit: '',
			kompdet_rapkprice: 0,
			kompdet_price: 0
		});
		editor_m_jobdet.stopEditing();
		jobdetDataStore.insert(0, edit_m_jobdet);
		//t_komp_jobdetListEditorGrid.getView().refresh();
		t_komp_jobdetListEditorGrid.getSelectionModel().selectRow(0);
		editor_m_jobdet.startEditing(0);
	}
	
	
	function m_detail_add(btn, ev) {
		var editor_detail= new t_komp_detailListEditorGrid.store.recordType({
			rapkdet_id: 0,
			jobdet_id: '',
			rapkdet_volume: 0,
			rapkdet_unit: '',
			rapkdet_price: 0
		});
		editor_detaillist.stopEditing();
		detailDataStore.insert(0, editor_detail);
		//rapkdetTempListGrid.getView().refresh();
		t_komp_detailListEditorGrid.getSelectionModel().selectRow(0);
		editor_detaillist.startEditing(0);
	}
	
	
	function m_group_add(){
		var edit_m_jobdet= new t_komp_groupListEditorGrid.store.recordType({
			group_id: 0,
			group_uraian: '',
			group_publish: 0
		});
		editor_group.stopEditing();
		groupDataStore.insert(0, edit_m_jobdet);
		//t_komp_jobdetListEditorGrid.getView().refresh();
		t_komp_groupListEditorGrid.getSelectionModel().selectRow(0);
		editor_group.startEditing(0);
	}
	
	function m_jobdet_confirm_delete(){
		// only one record is selected here
		if(t_komp_jobdetListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', m_jobdet_delete);
		} else if(t_komp_jobdetListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', m_jobdet_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk dihapus',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	function group_delete(btn){
		if(btn=='yes'){
			var s = t_komp_groupListEditorGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				var newdata = t_komp_groupListEditorGrid.getSelectionModel().getSelected().data;
                
                Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_komp&m=t_kompdet_grouptemp_delete',
					params: {
						group_id	: r.data.group_id
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								t_komp_groupListEditorGrid.getStore().reload({
									callback: function(opts, success, response){
										t_komp_groupListEditorGrid.getSelectionModel().selectRow(0);
									}
								});
								
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
			}
			
		}
		
		t_komp_groupListEditorGrid.detDelBtn.disable();
		
	} 
	
	
		
	function m_group_confirm_delete(){
		// only one record is selected here
		if(t_komp_groupListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', group_delete);
		} else if(t_komp_groupListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', group_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk dihapus',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	function detail_delete(btn){
		if(btn=='yes'){
			if (t_komp_detailListEditorGrid.isVisible()){
				grid = t_komp_detailListEditorGrid;
				var itemsdelete = [];
			}else{
				grid = t_komp_detailListEditorGrid;
			}
			var rdata = null;
			var s = grid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				rdata = r.data;
				master_store = grid.getStore();
				master_store.remove(r);
				if (t_komp_detailListEditorGrid.isVisible()){
					itemsdelete.push(r.data.groupdettemp_id);
				}
			}
			if (t_komp_detailListEditorGrid.isVisible()){
				
				Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_komp&m=t_kompdet_detailtemp_delete',
					params: {
						ids	:  Ext.encode(itemsdelete)
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
							
								detail_total_rapk = 0;
								detail_total_komp = 0;
								
									groupstore = t_komp_groupListEditorGrid.getStore();
									for(var i=0;i<groupstore.getCount();i++){
										detail_total_komp +=  groupstore.getAt(i).data.group_kompprice;
										detail_total_rapk +=  groupstore.getAt(i).data.group_rapkprice;
									}
								
									detailallDataStore.load({
										callback: function(opts, success, response){
											for(var i=0;i<detailallDataStore.getCount();i++){
												var vol = detailallDataStore.getAt(i).data.rapkdet_volume;
												var hrg = detailallDataStore.getAt(i).data.kompdet_price;
												if(vol !== undefined && hrg !== undefined){
													detail_total_rapk += (detailallDataStore.getAt(i).data.rapkdet_volume * detailallDataStore.getAt(i).data.rapkdet_price);
													detail_total_komp += (detailallDataStore.getAt(i).data.kompdet_volume * detailallDataStore.getAt(i).data.kompdet_price);
												}
											}
											komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
											komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
										}
									});
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
			}
		}  
	}

	
	function m_detail_confirm_delete(){
		// only one record is selected here
		if(t_komp_detailListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod ini?', detail_delete);
		} else if(t_komp_detailListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation','Apakah Anda yakin menghapus rekod-rekod ini?', detail_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Tidak ada data yang terpilih untuk dihapus',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	
	function t_kompdet_grouptemp_truncate(){
		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_komp&m=t_kompdet_grouptemp_truncate',
			success: function(response){
				var result=eval(response.responseText);
			},
			failure: function(response){
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});
			}
		});
	}
	t_kompdet_grouptemp_truncate();
	
	function m_jobdet_delete(btn){
		if(btn=='yes'){
			var s = t_komp_jobdetListEditorGrid.getSelectionModel().getSelections();
			for(var i = 0, r; r = s[i]; i++){
				jobdetDataStore.remove(r);
			}


			var detail_total_rapk = 0;
    		var detail_total_komp = 0;
    		
    		var detail_store = t_komp_jobdetListEditorGrid.getStore();
    		for(var i=0;i<detail_store.getCount();i++){
        		var vol = detail_store.getAt(i).data.kompdet_vol;
        		var hrg = detail_store.getAt(i).data.kompdet_price;
        		if(vol !== undefined && hrg !== undefined){
        			detail_total_rapk+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_rapkprice);
        			detail_total_komp+= (detail_store.getAt(i).data.kompdet_vol * detail_store.getAt(i).data.kompdet_price);
        		}
    			
    		}
    		komprapk_jobdet_total_cfField.setValue(formatCurrency(detail_total_rapk));
    		komp_jobdet_total_cfField.setValue(formatCurrency(detail_total_komp));
		}  
	}
	
	function nosurat_validation(){
		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_komp&m=get_nosurat_byvendor',
			params: {
				vendor	: komp_vendorField.getValue(),
				nosurat	: komp_noField.getValue()
			},
			success: function(response){
				var result=eval(response.responseText);
				if(result==0){
					komp_validornotField.setText("Invalid");
					/* Ext.MessageBox.show({
					   title: 'Warning',
					   msg: 'No. Surat tidak valid!',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'save',
					   icon: Ext.MessageBox.WARNING
					}); */
					komp_noField.reset();
					komp_noField.setValue(null);
				}else{
					komp_validornotField.setText("Valid");
				}
			},
			failure: function(response){
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});
			}
		});
	}
  	
  	/* END FUNCTION */

	/* START CONTROL PERMISSION */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		t_komp_gbtn_add.setVisible(false);
	}else{
		t_komp_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		t_komp_gbtn_update.setVisible(false);
	}else{
		t_komp_gbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		t_komp_gbtn_delete.setVisible(false);
	}else{
		t_komp_gbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_komp_btn_Save.setVisible(false);
	}else{
		t_komp_btn_Save.setVisible(true);
	}
	/* END CONTROL PERMISSION */
	
});
</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_komp_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_komp"></div>
        <div id="elwindow_t_komp_search"></div>
    </div>
</div>
</body>
</html>